package com.zlzxm.shoesmarket.view.activity;

import android.content.Context;
import android.content.Intent;

import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.adapter.ADMarketInfo;
import com.zlzxm.shoesmarket.view.widget.MarketView;
import com.zlzxm.shoesmarket.view.widget.simpleead.SimpleHead;
import com.zlzxm.shoesmarket.viewmodel.VMWholesaleMarket;

/**
 * CREATE BY zlzxm ON 4/12/21
 */
public class ACWholesaleMarket extends BaseActivity{

    public static void start(Context context){

        Intent intent = new Intent(context, ACWholesaleMarket.class);

        context.startActivity(intent);
    }

    private VMWholesaleMarket vmWholesaleMarket;

    private RecyclerView rvMarketInfo;

    private ADMarketInfo adMarketInfo = new ADMarketInfo(null);

    private MarketView marketView;


    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.ac_wholesale_market);
        SimpleHead simpleHead = ZViewHelp.findById(this,R.id.head);
        simpleHead.setTitle("批发市场");
        simpleHead.setOnItemclicklistener(this::finish);
        marketView  = ZViewHelp.findById(this,R.id.marketView);
        rvMarketInfo = ZViewHelp.findById(this,R.id.rvMarketInfo);
        rvMarketInfo.setLayoutManager(new LinearLayoutManager(this));


    }

    @Override
    protected void initViewModule() {
        super.initViewModule();

        vmWholesaleMarket = new ViewModelProvider(this).get(VMWholesaleMarket.class);

        vmWholesaleMarket.getLiveMarket().observe(this, marketView::updateMarkets);

        vmWholesaleMarket.getLiveMarketInfo().observe(this,adMarketInfo::setList);

    }

    @Override
    protected void initData() {
        super.initData();
        rvMarketInfo.setAdapter(adMarketInfo);
        vmWholesaleMarket.requestMarkets();
        vmWholesaleMarket.requestMarketInfo();
    }
}
